﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;

namespace YAMN_Cinemas.Presentation
{
    public partial class Registrationform1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected void TextBox1_TextChanged(object sender, EventArgs e)
        {

        }

        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {
            //Calendar2.Visible = true;
        }

        protected void Calendar2_SelectionChanged(object sender, EventArgs e)
        {
        //    TextBox6.Text = Calendar2.SelectedDate.ToShortDateString();
        //    Calendar2.Visible = false;
        }
        private void clearfield()
        {
            //TextBox1.Text = string.Empty;
            //TextBox2.Text = string.Empty;
            //TextBox3.Text = string.Empty;
            //TextBox4.Text = string.Empty;
            //TextBox5.Text = string.Empty;
            //TextBox6.Text = string.Empty;
            //TextBox7.Text = string.Empty;
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            string username = txt_UserName.Text;
            string password = txt_Password.Text;
            string email = txt_Email.Text;
            string role="User";
            MembershipCreateStatus status;
            MembershipUser user = Membership.CreateUser(username, password, email, null, null, true, out status);
            switch (status)
            {
                case MembershipCreateStatus.DuplicateUserName:
                    lbl_Status.Text= "Username already exists. Please enter a different user name.";
                    break;

                case MembershipCreateStatus.DuplicateEmail:
                    lbl_Status.Text= "A username for that e-mail address already exists. Please enter a different e-mail address.";
                    break;

                case MembershipCreateStatus.InvalidPassword:
                    lbl_Status.Text= "The password provided is invalid. Please enter a valid password value.";
                    break;

                case MembershipCreateStatus.InvalidEmail:
                    lbl_Status.Text= "The e-mail address provided is invalid. Please check the value and try again.";
                    break;

                case MembershipCreateStatus.InvalidAnswer:
                    lbl_Status.Text= "The password retrieval answer provided is invalid. Please check the value and try again.";
                    break;

                case MembershipCreateStatus.InvalidQuestion:
                    lbl_Status.Text= "The password retrieval question provided is invalid. Please check the value and try again.";
                    break;

                case MembershipCreateStatus.InvalidUserName:
                    lbl_Status.Text= "The user name provided is invalid. Please check the value and try again.";
                    break;

                case MembershipCreateStatus.ProviderError:
                    lbl_Status.Text= "The authentication provider lbl_Status.Text=ed an error. Please verify your entry and try again. If the problem persists, please contact your system administrator.";
                    break;

                case MembershipCreateStatus.UserRejected:
                    lbl_Status.Text= "The user creation request has been canceled. Please verify your entry and try again. If the problem persists, please contact your system administrator.";
                    break;
                case MembershipCreateStatus.Success:
                    Roles.AddUserToRole(username, role);
                    TheatreEntities cntx = new TheatreEntities();
                            User addmember = new User();
                            addmember.UserID = username;
                            addmember.Password = password;
                            addmember.EmailID = txt_Email.Text;
                            addmember.Role = "User";
                            addmember.Contact = "123456";

                            addmember.DOB = DateTime.Now;
                            addmember.Name = username;
                            cntx.AddToUsers(addmember);
                            clearfield();
                            cntx.SaveChanges();
                    lbl_Status.Text= "You Account was created Successfully";
                    break;
            }
            



            



            //TheatreEntities te = new TheatreEntities();
            //List<string> userid = new List<string>();
            //string id_Name;
            //var q = (from id in te.Users
            //         where id.UserID == TextBox1.Text
            //         select id.UserID);
            //userid = q.ToList();
            //id_Name = userid.First();

            //if(TextBox1.Text!=id_Name)
            //{
            //    using (TheatreEntities cntx = new TheatreEntities())
            //    {
            //        User addmember = new User();
            //        addmember.UserID = TextBox1.Text;
            //        addmember.Password = TextBox2.Text;
            //        addmember.EmailID = TextBox4.Text;
            //        addmember.Role = "User";
            //        addmember.Contact = TextBox5.Text;

            //        addmember.DOB = Convert.ToDateTime(TextBox6.Text);
            //        addmember.Name = TextBox7.Text;
            //        cntx.AddToUsers(addmember);
            //        clearfield();
            //        cntx.SaveChanges();

            //    }   
            //}
            //else
            //{           
            //    TextBox1.Text = "User name already exists";
            //    TextBox2.Text = string.Empty;
            //    TextBox3.Text = string.Empty;
            //    TextBox4.Text = string.Empty;
            //    TextBox5.Text = string.Empty;
            //    TextBox6.Text = string.Empty;
            //    TextBox7.Text = string.Empty;
            //}
        }


        

        protected void Button2_Click(object sender, EventArgs e)
        
            {
                

                Response.Redirect("http://localhost:6500/Presentation/WelcomePage1.aspx");
            }
        
       

        
    }
}
